package me.stone.stanimeclient.page.recommend

import androidx.paging.PagingSource
import androidx.paging.PagingState
import me.stone.stanimeclient.core.data.domain.data.ListRecommendRepository
import me.stone.stanimeclient.core.model.FanSimpleItem

class RecommendPagingSource(
    private val repository: ListRecommendRepository
) : PagingSource<Unit, FanSimpleItem>() {

    override fun getRefreshKey(state: PagingState<Unit, FanSimpleItem>): Unit? {
        return null
    }

    override suspend fun load(params: LoadParams<Unit>): LoadResult<Unit, FanSimpleItem> {
        return try {
            val data = repository.listRecommend()
            LoadResult.Page(data.data, null, null)
        } catch (e: Exception) {
            LoadResult.Error(e)
        }
    }

}